//
//  JCFontUtil.swift
//  JCPublicKit
//
//  Created by JasonLee on 2020/5/13.
//

import Foundation

class JCFontUtil: NSObject {
    
    @objc enum PingFangSCType: Int {
        /// 极细体
        case ultralight = 0
        /// 细体
        case light
        /// 纤细体
        case thin
        /// 常规体
        case regular
        /// 中粗体
        case semibold
        /// 中黑体
        case medium
        
        var fontName: String {
            switch self {
            case .ultralight:   return "PingFangSC-Ultralight"
            case .light:        return "PingFangSC-Light"
            case .thin:         return "PingFangSC-Thin"
            case .regular:      return "PingFangSC-Regular"
            case .semibold:     return "PingFangSC-Semibold"
            case .medium:       return "PingFangSC-Medium"
            }
        }
    }
    
    @objc static func pingFangSCUltralight(size: CGFloat) -> UIFont {
        return UIFont(name: PingFangSCType.ultralight.fontName, size: size) ?? UIFont.systemFont(ofSize: size)
    }
    @objc static func pingFangSCLight(size: CGFloat) -> UIFont {
        return UIFont(name: PingFangSCType.light.fontName, size: size) ?? UIFont.systemFont(ofSize: size)
    }
    @objc static func pingFangSCThin(size: CGFloat) -> UIFont {
        return UIFont(name: PingFangSCType.thin.fontName, size: size) ?? UIFont.systemFont(ofSize: size)
    }
    @objc static func pingFangSCRegular(size: CGFloat) -> UIFont {
        return UIFont(name: PingFangSCType.regular.fontName, size: size) ?? UIFont.systemFont(ofSize: size)
    }
    @objc static func pingFangSCSemibold(size: CGFloat) -> UIFont {
        return UIFont(name: PingFangSCType.semibold.fontName, size: size) ?? UIFont.systemFont(ofSize: size)
    }
    @objc static func pingFangSCMedium(size: CGFloat) -> UIFont {
        return UIFont(name: PingFangSCType.medium.fontName, size: size) ?? UIFont.systemFont(ofSize: size)
    }
}

extension UIFont {
    @objc static func jc_pingFangSCUltralight(size: CGFloat) -> UIFont {
        JCFontUtil.pingFangSCUltralight(size: size)
    }
    @objc static func jc_pingFangSCLight(size: CGFloat) -> UIFont {
        JCFontUtil.pingFangSCLight(size: size)
    }
    @objc static func jc_pingFangSCThin(size: CGFloat) -> UIFont {
        JCFontUtil.pingFangSCThin(size: size)
    }
    @objc static func jc_pingFangSCRegular(size: CGFloat) -> UIFont {
        JCFontUtil.pingFangSCRegular(size: size)
    }
    @objc static func jc_pingFangSCSemibold(size: CGFloat) -> UIFont {
        JCFontUtil.pingFangSCSemibold(size: size)
    }
    @objc static func jc_pingFangSCMedium(size: CGFloat) -> UIFont {
        JCFontUtil.pingFangSCMedium(size: size)
    }
}
